package intermouse;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Console;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * A program működését indító osztály.
 * 
 * @author Demény Fruzsina Gyöngyi, Sőre András
 * @version 1.0
 * @since 2013-03-23
 */
public class Main {

	static BufferedReader reader = null;
	
	/**
	 * @param args
	 * 
	 */
	public static void main(String[] args){
		
		String inputFilename=null;
		String outputFilename=null;
		
		Level level=new Level();
				
		
		if(args.length==1)
			inputFilename=args[0];
		else if(args.length==2){
			inputFilename=args[0];
			outputFilename=args[1];
		}
		
		try {
				if(inputFilename!=null)
				reader = new BufferedReader(new FileReader(args[0]));
				if(outputFilename!=null)
					TestCommandParser.writer = new BufferedWriter(new FileWriter(args[1]));
			} catch (FileNotFoundException e1) {
				TestCommandParser.print("File not found, exiting...");
				System.exit(-1);
			} catch (IOException e1) {
				TestCommandParser.print("Cannot open output file, logging is disabled!");
			}
		if(reader==null)
			reader = new BufferedReader(new InputStreamReader(System.in));
		
		while (true) {
			try {
				TestCommandParser.interpret(reader.readLine(), level);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
}
